package com.example.demo;

import org.springframework.boot.*;
import org.springframework.boot.autoconfigure.*;
import org.springframework.web.bind.annotation.*;

import java.net.Inet4Address;
import java.net.InetAddress;
import java.net.UnknownHostException;

@RestController
@EnableAutoConfiguration
public class HelloController {

    @RequestMapping("/")
    String home() {
        return "Hello World!!";
    }

    @RequestMapping("/test")
    String test() {
        return "test test!!!!!!!";
    }

    @RequestMapping("/host")
    String host() {
        InetAddress localhost = null;
        try {
            localhost = InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }
        System.out.println("hostName:" + localhost.getHostName());
        System.out.println("hostAddress:" + localhost.getHostAddress());
        return localhost.getHostAddress() + localhost.getHostName();
    }

    public static void main(String[] args) throws Exception {
        SpringApplication.run(HelloController.class, args);
    }

}